import java.util.Scanner;

public class Prime {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            in.nextLine();
            for (int i = 0; i < n; i++) {
                long a = in.nextLong();
                long b = in.nextLong();
                in.nextLine();
                if ((a != 1 && !isPrime(a)) || (b != 1 && !isPrime(b))) {
                    System.out.println("NO");
                } else {
                    if ((a == 1 && b == 1) || (a != 1 && b != 1)) {
                        System.out.println("NO");
                    } else {
                        System.out.println("YES");
                    }
                }
            }
        }
    }

    private static boolean isPrime(long target) {
        if (target <= 1) return false;
        if (target == 2) return true;
        if (target % 2 == 0) return false;
        for (long i = 3; i * i <= target; i += 2) {
            if (target % i == 0) return false;
        }
        return true;
    }
}
